package cn.epsilon3.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

/**
 * json工具类
 * alibaba fastjson2
 *
 * @author epsilon3
 * @version 1.0
 * @date 2023/07/25
 */
public class E3JsonKit {

    public static JSONObject initJson(int initialCapacity) {
        return new JSONObject(initialCapacity);
    }

    public static JSONObject obj2Json(Object obj) {
        return JSONObject.parseObject(obj2JsonStr(obj));
    }

    public static JSONArray obj2Json(Object[] objs) {
        return JSONArray.parseArray(obj2JsonStr(objs));
    }

    public static String obj2JsonStr(Object obj) {
        return JSON.toJSONString(obj);
    }
}
